import { showNotify,showConfirmDialog } from 'vant';

const warning = (options = {}) =>
{
    let message = typeof options === 'string' ? options : '未知信息';
    let duration = 2000;
    let onClose = () => {}

    if(typeof options === 'object')
    {
        message = options.message ?? message;
        duration = options.duration ?? duration;
        onClose = typeof options.onClose === 'function' ? options.onClose : onClose;
    }

    showNotify({
        type:'warning',
        message:message,
        duration,
        onClose:onClose
    })
}
const success = (options = {}) =>
    {
        let message = typeof options === 'string' ? options : '未知信息';
        let duration = 2000;
        let onClose = () => {}
    
        if(typeof options === 'object')
        {
            message = options.message ?? message;
            duration = options.duration ?? duration;
            onClose = typeof options.onClose === 'function' ? options.onClose : onClose;
        }
    
        showNotify({
            type:'success',
            message:message,
            duration,
            onClose:onClose
        })
    }

export default {
    install(app)
    {
        app.config.globalProperties.$warning = warning;
        app.config.globalProperties.$success = success;
        app.config.globalProperties.$confirm = showConfirmDialog;
    }
}